package com.moweilin.mo_utils.cli;

import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;

import java.util.ArrayList;
import java.util.List;

import static com.moweilin.mo_utils.cli.HelpCommand.NAME;

/**
 * Created by moweilin on 2017/2/15.
 */
@Parameters(commandNames = {NAME},commandDescription = "show usage information.")
public class HelpCommand {
    public static final String NAME = "help";
    @Parameter(description = "--commands to show help")
    private List<String> commandList = new ArrayList<>();

    public boolean execute(JCommander commander) {
        if(commandList == null || commandList.isEmpty()) {
            commander.setProgramName("");
            commander.usage();
        }else {
            commandList.forEach(command -> {
                JCommander sub = commander.getCommands().get(command);
                sub.usage();
            });
        }
        return true;
    }
}
